const app = getApp();
var server = require('../../utils/server');
var common = require('../../utils/common');
var hideTimer = null;
var countdown = 60;
var settime = function (that) {
  if (countdown == 0) {
    that.setData({
      is_show: true
    })
    countdown = 60;
    return;
  } else {
    that.setData({
      is_show: false,
      last_time: countdown
    })
    countdown--;
  }
};
Page({
  data: {
    address_id: "",
    location: "",
    orderInfo: [],
    addressInfo: [],
    showScoreInput: false,
    newScoreCardNum: '',
    scoreCardNum: '',
    remark: "",
    showOverArea: false,
    isShowCoupon: false,
    couponanimationData: [],
    isNoSelect: false,
    couponList: [],
    invalidCouponList: [],
    showAddrStatus: false,
    showGifTip: false,
    channelid: "",
    timestap: "",
    isFocus: false,
    memoWordsNum: 0,
    isShowTickets: false,
    ticketanimationData: [],
    validTicketList: [],
    invalidTicketList: [],
    isSingleCard: 2,
    curCardTicketTel: '', //校验卡券
    curCardTicketId: '',
    curCardTicketAmount: '',
    isShowCardVerify: false,
    curCardVerifyCode: '',
    last_time: '',
    is_show: true,
    mesgCode: '',
    isGet: false,
    isVerifyPay: false,
    couponSelectNum: 0,
    curCouponTab: 0
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  onShow() {
    this.setData({
      timestap: Date.parse(new Date())
    })
    wx.getStorage({
      key: 'channelid',
      success: response => {
        this.setData({
          channelid: response.data
        })
        console.log(response.data)
        if (response.data == '3000000') { //特殊小程序码显示支付抵用券gif弹框
          server.postJSON(common.basePath + 'user/isshow', {
            "type": "gif",
            "is_checked": 0
          }, res => {
            if (res.data.errno == '0') {
              this.setData({
                showGifTip: res.data.data == 1 ? true : false
              })
            } else {
              common.showErrorToast(res.data.errmsg);
            }
          })
        }
      },
      fail: response => {
        console.log('nochannel')
      }
    })
    this.setData({
      location: app.globalData.location == null ? '无' : app.globalData.location
    })
    if (app.globalData.hyzgAddrId != "") {
      this.checkAddr(app.globalData.hyzgAddrId)
    } else {
      wx.getStorage({
        key: 'memberaccountlist',
        success: res => {
          var data = res.data;
          var eventid = data.event_id;
          if (app.globalData.isRefreshAccountList) {
            var list = [];
            data.goods_list.forEach((item, index) => {
              list.push({
                "goods_id": item.goods_id,
                "quantity": item.quantity
              })
            })
            var accountParam = {
              "address_id": data.address.address_id,
              "event_id": eventid,
              "coupon_list": [],
              "card_voucher_list": [],
              "list": list
            }
            server.postJSON(common.storePath + 'event/check/', accountParam, resp => {
              if (resp.data.errno == '0') {
                resp.data.data.event_id = eventid;
                this.dealWithAccountList(resp.data.data)
                wx.setStorage({
                  key: 'memberaccountlist',
                  data: resp.data.data,
                  success: res => {}
                })
              } else {
                common.showErrorToast(res.data.errmsg)
              }
            })
          } else {
            this.dealWithAccountList(data)
          }
        },
      })
    }
  },
  dealWithAccountList(data) {
    let couponSelectNum = 0;
    data.coupon_list.forEach(function (item) {
      if (item.is_checked_has == 1) {
        couponSelectNum++;
      }
    })
    var validTicketList = data.card_voucher_list.filter((item, index) => {
      return item.error == '';
    })
    var invalidTicketList = data.card_voucher_list.filter((item, index) => {
      return item.error != '';
    })
    var curCardTicketInfo = validTicketList.filter((item, index) => {
      return item.is_checked == 1;
    })
    this.setData({
      orderInfo: data,
      scoreCardNum: data.score_mobile,
      addressInfo: JSON.stringify(data.address) == "{}" ? [] : data.address,
      address_id: JSON.stringify(data.address) == "{}" ? '' : data.address.address_id,
      backup_tel: data.backup_tel,
      couponList: data.coupon_list,
      invalidCouponList: data.coupon_list_unavailable,
      couponSelectNum: couponSelectNum,
      validTicketList: validTicketList,
      invalidTicketList: invalidTicketList,
      isSingleCard: curCardTicketInfo.length > 0 ? curCardTicketInfo[0].once : 2,
      curCardTicketTel: curCardTicketInfo.length > 0 ? curCardTicketInfo[0].mobile : '',
      isShowCardVerify: false
    })
    this.data.curCardTicketId = curCardTicketInfo.length > 0 ? curCardTicketInfo[0].bind_id : '';
    this.data.curCardTicketAmount = curCardTicketInfo.length > 0 ? curCardTicketInfo[0].balance : '';
    this.data.eventid = data.event_id;

  },
  onHide() {
    app.globalData.hyzgAddrId = "";
    app.globalData.isRefreshAccountList = false;
    clearTimeout(hideTimer);
  },
  onUnload() {
    app.globalData.hyzgAddrId = "";
    app.globalData.isRefreshAccountList = false;
    clearTimeout(hideTimer);
  },
  hideToast() {
    hideTimer = setTimeout(function () {
      wx.hideToast()
    }, 3500)
  },
  showScoreCardPop() {
    this.setData({
      showScoreInput: true
    })
  },
  hideScoreCard() {
    this.setData({
      showScoreInput: false
    })
  },
  inputCardNum(e) {
    this.setData({
      newScoreCardNum: e.detail.value
    })
  },
  getBackUpTel(e) {
    this.setData({
      backup_tel: e.detail.value
    })
  },
  checkScoreCard() {
    server.postJSON(common.basePath + 'member/bindscore/', {
      "mobile": this.data.newScoreCardNum
    }, res => {
      if (res.data.errno == "0") {
        this.setData({
          showScoreInput: false,
          scoreCardNum: this.data.newScoreCardNum
        })
      } else {
        common.showErrorToast(res.data.errmsg);
      }
    })
  },

  showModal() {
    this.setData({
      showOverArea: false
    })
    wx.navigateTo({
      url: '../../pages/common/addrListsByCity?fromtype=0&&frompage=hyzg',
    })
  },
  checkAddr(addressid) {
    server.postJSON(common.storePath + 'event/checkAddress/', {
      "event_id": this.data.orderInfo.event_id,
      "address_id": addressid
    }, res => {
      if (res.data.errno == '0') {
        this.setData({
          addressInfo: res.data.data,
          address_id: addressid
        })
        this.data.orderInfo.address = res.data.data;
        wx.setStorage({
          key: 'memberaccountlist',
          data: this.data.orderInfo,
        })
      } else {
        this.setData({
          showOverArea: true
        })
        if (res.data.errno != '180003') {
          common.showErrorToast(res.data.errmsg)
        }
      }
    })
  },
  getRemark(e) {
    this.setData({
      remark: e.detail.value
    })
    if (this.data.remark.length <= 50) {
      this.setData({
        memoWordsNum: this.data.remark.length
      })
    }
  },
  pay() {
    app.globalData.orderType = 1;
    this.setData({
      isPayOk: true
    })
    var list = [],
      that = this;
    that.data.orderInfo.goods_list.forEach((item, index) => {
      list.push({
        "goods_id": item.goods_id,
        "quantity": item.quantity
      })
    })
    console.log(list)
    var param = {
      "address_id": that.data.address_id,
      "event_id": that.data.orderInfo.event_id,
      "list": list,
      "score_mobile": that.data.scoreCardNum,
      "memo": that.data.remark,
      "backup_tel": that.data.backup_tel,
      "coupon_list": that.data.couponList
    };
    if (that.data.address_id == '') {
      that.setData({
        showAddrStatus: true
      })
    } else {
      var selectedTicketList = [];
      if (this.data.validTicketList.length > 0) {
        selectedTicketList = this.data.validTicketList.filter((item, index) => {
          return item.is_checked == 1;
        })
      }
      if (that.data.channelid != "") {
        param.channel_id = that.data.channelid;
        console.log(param, 'addparam')
        if (selectedTicketList.length > 0) {
          //验证电子卡券
          this.setData({
            isShowCardVerify: true,
            isVerifyPay: false
          })
        } else {
          that.addOrder(param);
        }
      } else {
        if (selectedTicketList.length > 0) {
          //验证电子卡券
          this.setData({
            isShowCardVerify: true,
            isVerifyPay: false
          })
        } else {
          that.addOrder(param);
        }
      }
    }
  },
  goToChooseAddr() {
    this.setData({
      showAddrStatus: false,
      isPayOk: false
    })
    wx.navigateTo({
      url: '../../pages/common/addrListsByCity?fromtype=0&&frompage=hyzg',
    })
  },
  addOrder(param) {
    param.service_list = this.data.orderInfo.service_list;
    if (app.globalData.zgAccountRandom == '') {
      app.globalData.zgAccountRandom = Math.random();
      server.postJSON(common.storePath + 'event/order/', param, res => {
        app.globalData.zgAccountRandom = '';
        if (res.data.errno == "0") {
          app.globalData.refreshTag = true;
          app.globalData.isAccount = true;
          var orderId = res.data.data.order_id,
            realAmount = res.data.data.real_amount; //实付金额
          wx.setStorage({
            key: 'orderId',
            data: orderId,
            success: ret => {
              if (realAmount > 0) { //是否0元支付
                wx.hideLoading();
                if (app.globalData.sdkversion >= 282 && app.globalData.sdkversion != 1997 && app.globalData.sdkversion != 1991) {
                  server.postJSON(common.basePath + 'miniprogram/getnewtemplateid', {
                    "type": "event_pay"
                  }, res => {
                    if (res.data.errno == '0') {
                      console.log(res.data.data)
                      var ids = [];
                      (res.data.data).forEach((item, index) => {
                        ids.push(item)
                      })
                      var that = this;
                      console.log(ids)
                      wx.requestSubscribeMessage({
                        tmplIds: ids,
                        success(res) {
                          that.payByWx(orderId);
                        },
                        fail(res) {
                          console.log(res, 'fail')
                          that.payByWx(orderId);
                        }
                      })
                    } else {
                      common.showErrorToast(res.data.errmsg);
                    }
                  })
                } else {
                  var that = this;
                  wx.showModal({
                    title: '微信版本升级提示',
                    content: '当前微信版本过低，无法获得订阅消息通知，请升级最新微信版本。',
                    showCancel: false,
                    confirmText: "我知道了",
                    success(res) {
                      that.payByWx(orderId);
                    }
                  })
                }
              } else {
                this.setData({
                  isPayOk: false
                })
                if (app.globalData.sdkversion >= 282 && app.globalData.sdkversion != 1997 && app.globalData.sdkversion != 1991) {
                  server.postJSON(common.basePath + 'miniprogram/getnewtemplateid', {
                    "type": "event_pay"
                  }, res => {
                    if (res.data.errno == '0') {
                      console.log(res.data.data)
                      var ids = [];
                      (res.data.data).forEach((item, index) => {
                        ids.push(item)
                      })
                      var that = this;
                      console.log(ids)
                      wx.requestSubscribeMessage({
                        tmplIds: ids,
                        success(res) {
                          wx.redirectTo({
                            url: '../../pay/pages/paySuccess?orderId=' + orderId
                          })
                        },
                        fail(res) {
                          console.log(res, 'fail')
                          wx.redirectTo({
                            url: '../../pay/pages/paySuccess?orderId=' + orderId
                          })
                        }
                      })
                    } else {
                      common.showErrorToast(res.data.errmsg);
                    }
                  })
                } else {
                  var that = this;
                  wx.showModal({
                    title: '微信版本升级提示',
                    content: '当前微信版本过低，无法获得订阅消息通知，请升级最新微信版本。',
                    showCancel: false,
                    confirmText: "我知道了",
                    success(res) {
                      wx.redirectTo({
                        url: '../../pay/pages/paySuccess?orderId=' + orderId
                      })
                    }
                  })
                }

              }

            }
          })
        } else {
          if (res.data.errmsg == undefined) {
            common.showToast("数据出错啦T_T，请稍候再试 [-3]");
          } else {
            common.showToast(res.data.errmsg);
          }
          this.setData({
            isPayOk: false,
            isVerifyPay: false
          })
          this.hideToast();
        }
      })
    } else {
      app.globalData.zgAccountRandom = '';
      common.showErrorToast("订单已生成，请从订单列表查看");
      setTimeout(() => {
        wx.switchTab({
          url: '../../pages/order/orderIndex',
        })
      }, 2000);
    }
  },
  goToAddr(e) {
    console.log(e)
    wx.navigateTo({
      url: '../../address_manage/pages/editAddr?addrId=' + e.currentTarget.dataset.id + '&&addrType=4'
    })
  },
  showCoupons() {
    this.setData({
      isPayOk: true
    })
    // 显示遮罩层
    var animation1 = wx.createAnimation({
      duration: 300,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation1
    this.animation.translateY(500).step()
    this.setData({
      couponanimationData: this.animation.export(),
      isShowCoupon: !this.data.isShowCoupon
    })
    setTimeout(function () {
      this.animation.translateY(0).step()
      this.setData({
        couponanimationData: this.animation.export()
      })
    }.bind(this), 200)
  },
  cancelUseCoupons() {
    wx.getStorage({
      key: 'memberaccountlist',
      success: res => {
        console.log(res)
        this.setData({
          couponList: res.data.coupon_list,
          isPayOk: false
        })
      },
    })

    this.hideCouponList();
  },
  selectCoupon(e) {
    var vouchertype = e.currentTarget.dataset.vouchertype,
      curVoucherId = e.currentTarget.dataset.voucherid;
    console.log(this.data.couponList)
    if (vouchertype == 4) {
      this.data.couponList.forEach(function (item) {
        if (item.goods_type == vouchertype) {
          item.is_checked = 1;
          if (item.coupon_id == curVoucherId) {
            item.is_checked_has = item.is_checked_has == 1 ? 0 : 1
          }
        } else {
          item.is_checked_has = 0;
          item.is_checked = 0;
        }
      })
      this.setData({
        couponList: this.data.couponList
      })
    } else {
      this.data.couponList.forEach(function (item) {
        if (item.goods_type == vouchertype) {
          if (item.coupon_id != curVoucherId) {
            item.is_checked = 0;
            item.is_checked_has = 0;
          }
          if (item.coupon_id == curVoucherId) {
            item.is_checked = 1;
            console.log(item.is_checked_has, curVoucherId)
            item.is_checked_has = item.is_checked_has == 1 ? 0 : 1;
            console.log(item.is_checked_has, curVoucherId)
          }
        } else {
          item.is_checked_has = 0;
          item.is_checked = 0;
        }
        console.log(item)
      })
      this.setData({
        couponList: this.data.couponList
      })
    }

    let couponSelectNum = 0;
    this.data.couponList.forEach(function (item) {
      if (item.is_checked_has == 1) {
        couponSelectNum++;
      }
    })
    if (couponSelectNum == 0) {
      this.data.couponList.forEach(function (item) {
        item.is_checked = 1;
      })
      this.setData({
        couponList: this.data.couponList
      })
    }
    console.log(this.data.couponList)

  },
  hideCouponList() {
    var animation1 = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation1
    this.animation.translateY(300).step()
    this.setData({
      couponanimationData: this.animation.export(),
      isShowCoupon: !this.data.isShowCoupon,
      curCouponTab: 0
    })
    setTimeout(function () {
      this.animation.translateY(0).step()
      this.setData({
        couponanimationData: this.animation.export()
      })
    }.bind(this), 200)
  },
  confirmUseCoupon() {
    this.hideCouponList();
    app.globalData.isRefreshAccountList = false;
    var list = [];
    this.data.orderInfo.goods_list.forEach((item, index) => {
      list.push({
        "goods_id": item.goods_id,
        "quantity": item.quantity
      })
    })
    console.log(this.data.couponList)
    if (this.data.couponList.length > 0) {
      this.data.param = {
        "address_id": this.data.address_id,
        "event_id": this.data.eventid,
        "coupon_list": this.data.couponList,
        "coupon_list_unavailable": this.data.invalidCouponList,
        "service_list": this.data.orderInfo.service_list,
        // "card_voucher_list": this.data.validTicketList.concat(this.data.invalidTicketList),
        "list": list
      }
      server.postJSON(common.storePath + 'event/check/', this.data.param, res => {
        this.setData({
          isPayOk: false
        })
        if (res.data.errno == '0') {
          var data = res.data.data;
          data.event_id = this.data.eventid;
          this.dealWithAccountList(data);
          wx.setStorage({
            key: 'memberaccountlist',
            data: data,
            success: res => {}
          })
        } else {
          common.showErrorToast(res.data.errmsg)
        }
      })
    } else {
      this.setData({
        isPayOk: false
      })
    }
  },
  closeGifPop() {
    server.postJSON(common.basePath + 'user/isshow', {
      "type": "gif",
      "is_checked": 1
    }, res => {
      if (res.data.errno == '0') {
        this.setData({
          showGifTip: false
        })
      } else {
        common.showErrorToast(res.data.errmsg);
      }
    })
    server.postJSON(common.basePath + 'user/isshow', { //记录该gif下次不再展示
      "type": "gif",
      "is_checked": 1
    }, res => {
      if (res.data.errno == '0') {
        this.setData({
          showGifTip: false
        })
      } else {
        common.showErrorToast(res.data.errmsg);
      }
    })
    wx.removeStorage({
      key: 'channelid',
      success: function (res) {
        console.log('clearcid')
      },
    })
  },
  payByWx(orderid) {
    app.globalData.isBindYcCard = false;
    this.data.orderid = orderid;
    this.setData({
      isPayOk: true
    })
    var param = {
      "currency": '63',
      "order_id": orderid
    }
    common.pay(param).then(res => {
      if (res.errno == "0") {
        var outtradeno = res.data.out_trade_no;
        app.actionReport('REQUEST_PAYMENT', {
          // 商户订单号(必须)
          out_trade_no: outtradeno,
          take_type: (this.data.deliverType != 1 && this.data.deliverType != 3) ? 'DELIVERY' : 'STORE',
        })
        //发起支付
        var payParam = res.data;
        payParam.complete = function (ret3) {
          common.showLoading("支付中...");
          //支付成功
          var isSuc = ret3.errMsg == 'requestPayment:ok';
          console.log(isSuc)
          wx.reportAnalytics('pay_status', {
            paystatus: isSuc,
            orderid: orderid
          });
          if (isSuc) {
            wx.reportAnalytics('pay_success', {
              paystatus: isSuc,
              orderid: orderid
            });
            server.postJSON(common.storePath + 'order/payrespond/', {
              'out_trade_no': outtradeno
            }, resp => {
              wx.removeStorage({
                key: 'channelid',
                success: function (res) {
                  console.log('clearcid')
                },
              })
              wx.redirectTo({
                url: '../../pay/pages/paySuccess?orderId=' + orderid
              })
            })
          } else {
            wx.reportAnalytics('pay_fail', {
              paystatus: isSuc,
              orderid: orderid
            });
            wx.showToast({
              title: '支付失败',
              duration: 2000,
              complete: function () {
                wx.redirectTo({
                  url: '../../pay/pages/payFail?way=0&&orderId=' + orderid + '&&errmesg=微信支付失败'
                })
              }
            });
          }
        }
        wx.requestPayment(payParam);
      } else {
        if (res.errmsg == undefined) {
          common.showToast("数据出错啦T_T，请稍候再试 [-3]");
          time = setTimeout(function () {
            wx.hideToast()
          }, 3500)
        } else if (res.errno == "1000000") {
          this.setData({
            showStorePop: true,
            storeStatusInfo: res.data.status_tip
          })
        } else {
          common.showToast(res.errmsg);
        }
      }
    })
  },
  focusRemark() {
    console.log('focus')
    this.setData({
      isFocus: true
    })
  },
  confirmTextarea() {
    console.log('blur')
    this.setData({
      isFocus: false
    })
  },
  // 电子卡券
  showTickets() {
    this.setData({
      isPayOk: true
    })
    var animation1 = wx.createAnimation({
      duration: 450,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation1
    this.animation.translateY(600).step()
    this.setData({
      ticketanimationData: this.animation.export(),
      isShowTickets: !this.data.isShowTickets
    })
    setTimeout(function () {
      this.animation.translateY(0).step()
      this.setData({
        ticketanimationData: this.animation.export()
      })
    }.bind(this), 200)
    console.log(this.data.orderInfo.goods, 'showticket')
  },
  hideTicketList() {
    var animation1 = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation1
    this.animation.translateY(200).step()
    this.setData({
      ticketanimationData: this.animation.export(),
      isShowTickets: !this.data.isShowTickets
    })
    setTimeout(function () {
      this.animation.translateY(0).step()
      this.setData({
        ticketanimationData: this.animation.export()
      })
    }.bind(this), 200)
  },
  cancelUseTickets() {
    app.globalData.isRefreshAccountList = false;
    wx.getStorage({
      key: 'memberaccountlist',
      success: res => {
        console.log(res)
        this.data.validTicketList = [];
        this.data.invalidTicketList = [];
        var validTicketList = res.data.card_voucher_list.filter((item, index) => {
          return item.error == '';
        })
        var curCardTicketInfo = validTicketList.filter((item, index) => {
          return item.is_checked == 1;
        })
        var invalidTicketList = res.data.card_voucher_list.filter((item, index) => {
          return item.error != '';
        })
        this.setData({
          validTicketList: validTicketList,
          invalidTicketList: invalidTicketList,
          isSingleCard: curCardTicketInfo.length > 0 ? curCardTicketInfo[0].once : 2,
          isPayOk: false,
          curCardTicketTel: curCardTicketInfo.length > 0 ? curCardTicketInfo[0].mobile : ''
        })
        this.data.curCardTicketId = curCardTicketInfo.length > 0 ? curCardTicketInfo[0].bind_id : '';
        this.data.curCardTicketAmount = curCardTicketInfo.length > 0 ? curCardTicketInfo[0].balance : '';
        console.log(curCardTicketInfo)
      },
    })
    this.hideTicketList();
  },
  selectTicket(e) {
    var curVoucherId = e.currentTarget.dataset.voucherid,
      curVoucherError = e.currentTarget.dataset.verror;
    if (curVoucherError == '') {
      this.data.validTicketList.forEach(function (item) {
        if (item.bind_id == curVoucherId) {
          item.is_checked = item.is_checked == 1 ? 0 : 1;
        } else {
          item.is_checked = 0;
        }
        console.log(item)
      })
      this.setData({
        validTicketList: this.data.validTicketList
      })
    }
  },
  confirmUseTickets() {
    this.hideTicketList();
    if (this.data.validTicketList.length > 0) {
      var list = [];
      this.data.orderInfo.goods_list.forEach((item, index) => {
        list.push({
          "goods_id": item.goods_id,
          "quantity": item.quantity
        })
      })
      console.log(this.data.couponList)
      this.data.param = {
        "address_id": this.data.address_id,
        "event_id": this.data.eventid,
        "card_voucher_list": this.data.validTicketList.concat(this.data.invalidTicketList),
        "service_list": this.data.orderInfo.service_list,
        "list": list
      }
      server.postJSON(common.storePath + 'event/check/', this.data.param, res => {
        this.setData({
          isPayOk: false
        })
        if (res.data.errno == '0') {
          var data = res.data.data;
          data.event_id = this.data.eventid;
          this.dealWithAccountList(data);
          wx.setStorage({
            key: 'memberaccountlist',
            data: data,
            success: res => {}
          })
        } else {
          common.showErrorToast(res.data.errmsg)
        }
      })
    } else {
      this.setData({
        isPayOk: false
      })
    }
  },
  goToBindCard() {
    wx.navigateTo({
      url: '../../pages/memberCard/bindYcCard?type=account',
    })
  },
  getCardVerifyCode() {
    server.postJSON(common.basePath + 'card/verifybind/', {
      "mobile": this.data.curCardTicketTel,
      "type": 5,
      "real_amount": this.data.curCardTicketAmount
    }, res => {
      if (res.data.errno == "0") {
        this.setData({
          is_show: false,
          isGet: false
        })
        var that = this;
        settime(that);
      } else {
        this.setData({
          is_show: true,
          isGet: false
        })
        common.showErrorToast(res.data.errmsg);
      }
    })
  },
  inputCardVerifyCode(e) {
    this.setData({
      curCardVerifyCode: e.detail.value
    })
  },
  hideCardVerify() {
    this.setData({
      isShowCardVerify: false,
      isPayOk: false,
      isVerifyPay: false
    })
  },
  checkCardTicket() {
    if (this.data.curCardVerifyCode != '') {
      this.setData({
        isVerifyPay: true
      })
      var list = [];
      this.data.orderInfo.goods_list.forEach((item, index) => {
        list.push({
          "goods_id": item.goods_id,
          "quantity": item.quantity
        })
      })
      var param = {
        "address_id": this.data.address_id,
        "event_id": this.data.orderInfo.event_id,
        "list": list,
        "score_mobile": this.data.scoreCardNum,
        "memo": this.data.remark,
        "backup_tel": this.data.backup_tel,
        "coupon_list": this.data.couponList,
        "channel_id": this.data.channelid == '' ? '' : this.data.channelid,
        "card_voucher_list": this.data.validTicketList.concat(this.data.invalidTicketList),
        "verify": this.data.curCardVerifyCode
      };
      this.addOrder(param)
    } else {
      common.showErrorToast('请先输入验证码')
    }
  },
  changeCouponType(e) {
    this.setData({
      curCouponTab: e.currentTarget.dataset.id
    })
  },
  selectService(e) {
    this.setData({
      isPayOk: true
    })
    var list = [];
    this.data.orderInfo.goods_list.forEach((item, index) => {
      list.push({
        "goods_id": item.goods_id,
        "quantity": item.quantity
      })
    })
    var serviceid = e.currentTarget.dataset.serviceid;
    var newServiceList = this.data.orderInfo.service_list;
    newServiceList.forEach(function (item) {
      if (item.id == serviceid) {
        item.is_checked = item.is_checked == 1 ? 0 : 1;
      }
    })
    console.log(newServiceList)
    var accountParam = {
      "address_id": this.data.address_id,
      "event_id": this.data.eventid,
      "coupon_list": [],
      "card_voucher_list": [],
      "list": list,
      "service_list": newServiceList
    }
    this.eventCheck(accountParam)
  },
  eventCheck(param) {
    server.postJSON(common.storePath + 'event/check/', param, res => {
      this.setData({
        isPayOk: false
      })
      if (res.data.errno == '0') {
        var data = res.data.data;
        data.event_id = this.data.eventid;
        this.dealWithAccountList(data);
        wx.setStorage({
          key: 'memberaccountlist',
          data: data,
          success: res => {}
        })
      } else {
        common.showErrorToast(res.data.errmsg)
      }
    })
  }
})